// promise.all    
// promise 数组，所有数组到了一起resolve
const p1 = new Promise((resolve) => resolve('p1完成'))   
const p2 = new Promise((resolve,reject) => {
    setTimeout(() => {
        resolve('p2延迟1秒')
    },1000)
})  

const p3 = new Promise((resolve,reject) => {
    setTimeout(() => {
        resolve('p3延迟2秒')
    },2000)
})  

Promise.Myrace = (promises) => {
    return new Promise((resolve,reject) => {
        if(!Array.isArray(promises)){
            throw new Error('需要是数组')
        }   
        for (const item of promises) {
            Promise.resolve(item).then(resolve,reject)
        }
    })
}  

Promise.Myrace([p1,p2,p3])  
    .then(res => {
        console.log(res);
    }) 
    .catch(err => {
        console.log(err)
    })